package com.example.orderservice.controller;

import com.example.orderservice.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;


@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @RequestMapping("/create")
    public String create() {
        String orderId = UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("","order.queue","订单: " + orderId);
        return "发送成功";
    }

    @RequestMapping("/create2")
    public String create2() {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderId(UUID.randomUUID().toString());
        orderInfo.setName("商品" + new Random().nextInt(100));
        rabbitTemplate.convertAndSend("","order.queue", orderInfo);
        return "发送成功";
    }

}
